package com.bit.frige.sub.food;

import java.util.ArrayList;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

import com.bit.frige.MainActivity;
import com.bit.frige.R;
import com.bit.frige.DB.FoodDTO;
import com.bit.frige.DB.MyAdapter;

public class SubFoodCategoriActivity extends Activity {
        
        private ListView mList;
        private String[] arr = new String[]{
                        "육류","생선","해산물","채소","과일","유제품","음료","기타"
        };
        ArrayList<FoodDTO> list = new ArrayList<FoodDTO>();
        private int place;
        MyAdapter adapter;
        Button btn1;
        
        @SuppressLint("NewApi")
        @Override
        protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_sub_food_categori);
//                setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                Intent intent = getIntent();
                place = intent.getIntExtra("place", 0);
                
                
                mList = (ListView) findViewById(R.id.bigcate);
                FoodDTO food;
                for(int i=0;i<arr.length;i++){
                        food = new FoodDTO();
                        food.setId(i);
                        food.setFoodname(arr[i]);
                        list.add(food);
                }
                
                adapter = new MyAdapter(this, list);
                mList.setAdapter(adapter);
                
                mList.setOnItemClickListener(new OnItemClickListener() {

                        @Override
                        public void onItemClick(AdapterView<?> arg0, View view, int posion,
                                        long id) {
                                Intent intent = new Intent(getApplicationContext(),SubFoodCateActivity.class);
                                intent.putExtra("centno", ""+posion);
                                intent.putExtra("place", place);
                                startActivity(intent);                                                          
                                
                        }
                });
                
                btn1 = (Button) findViewById(R.id.button1);
                //홈이벤트
                btn1.setOnClickListener(new OnClickListener() {
                        
                        public void onClick(View v) {
                                Intent intentHome = new Intent(getApplicationContext(),MainActivity.class);
                                intentHome.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                                intentHome.putExtra("load", 1);
                                startActivity(intentHome);
                }
                });
                
        }

}
